/*
 * Example01.java
 *
 * Created on 19 gennaio 2008, 17.17
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package it.cnr.icib.flora2engine.examples;

import it.cnr.icib.flora2engine.Flora2;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import net.sourceforge.flora.javaAPI.src.FloraMethod;
import net.sourceforge.flora.javaAPI.src.FloraObject;

/**
 *
 * @author Nino
 */
public class Example02 {
    
    /** Creates a new instance of Example01 */
    public Example02() {
    }
    
    public static void main(String[] args) {
        
        String curDir = System.getProperty("user.dir");
        Flora2 session ;
        
        System.out.println(curDir);
        String OS= System.getProperties().getProperty("os.name");
        System.out.println(OS);
        
        
        if (OS.contains("Mac")){
            session = new Flora2(curDir+"/xsb_mac_337/config/i386-apple-darwin11.4.2/bin",
            		curDir+  "/xsb_mac_337/packages/flora2");

        }else if(OS.contains("Win")){
        	session = new Flora2(curDir+"/xsb_win_31/config/x86-pc-windows/bin",
        			curDir+"/xsb_win_31/packages/flora2");
        }else{
        	session = new Flora2(curDir+"/xsb_lin/config/x86-pc-windows/bin",
        			curDir+"/xsb_lin/packages/flora2");
        }
        
        session.setPath(curDir + "/florasrc");
        
        String fileName = "person";
        
        if(fileName == null || fileName.trim().length() == 0) {
            System.out.println("Invalid path to example file!");
            System.exit(0);
        }
        
          session.loadFile(fileName,"test");
        
        /* Examples of uses of the low-level Java-FLORA-2 API */
        
        
        /* Example of query with two variables */
        Vector<String> vars = new Vector<String>();
        vars.add("?X");
        vars.add("?Y");
        
        Iterator<HashMap<String,FloraObject>> allmatches =
                session.ExecuteQuery("?X[lavora_con -> ?Y]@test.",vars);
        System.out.println("Query:?X[lavora_con -> ?Y]@test.");
        
        HashMap<String,FloraObject> firstmatch;
        while (allmatches.hasNext()) {
            firstmatch = (HashMap<String,FloraObject>)allmatches.next();
            FloraObject Xobj = (FloraObject)firstmatch.get("?X");
            FloraObject Yobj = (FloraObject)firstmatch.get("?Y");
            System.out.println(Xobj+" lavora con: "+Yobj);
        }
        
        
        
        
        
        // Close session and good bye
        session.close();
        System.exit(0);
    }
}
